package zack.gateway.center.domain.docker.service;

import zack.gateway.center.application.ILoadBalancingService;
import zack.gateway.center.domain.docker.model.aggregates.NginxConfig;

import java.io.IOException;

/**抽象的负载均衡加载服务
 * @author A1793
 */
public abstract class AbstractLoadBalancingService implements ILoadBalancingService {

    /**
     * 加载负载均衡：
     * 1.更新本地的nginx.conf文件，（docker启动时，本地的conf挂载到了容器内部的conf）
     * 2.在nginx容器内部执行reload命令
     * @param nginxConfig
     */
    @Override
    public void updateNginxConfig(NginxConfig nginxConfig) throws IOException, InterruptedException {
        String filePath =  createNginxConfigFile(nginxConfig);
        refreshNginxConfig(nginxConfig.getNginxName());
    }

    public abstract String createNginxConfigFile(NginxConfig nginxConfig ) throws IOException;

    public abstract void refreshNginxConfig(String nginxName) throws InterruptedException, IOException;
}
